package com.ds.anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AnnoAop {
    @Before("execution(* com.ds.service.*.*.*(..))")
    public void before(){
        System.out.println("前置通知");
    }
    @After("execution(* com.ds.service.*.*.*(..))")
    public void after() throws Throwable {
        System.out.println("后置通知");
    }
    @AfterReturning("execution(* com.ds.service.*.*.*(..))")
    public void afterReturn(){
        System.out.println("方法返回后");
    }

    @AfterThrowing(throwing="ex",pointcut="execution(* com.ds.service.*.*.*(..))")
    public void AfterThrowing(Throwable ex){
        System.out.println("目标方法中抛出的异常:" + ex);
        System.out.println("模拟Advice对异常的修复...");
    }
    @Around("execution(* com.ds.service.*.*.*(..))")
    public void AroundMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕之前");
        //手动执行方法
        pjp.proceed();
        Signature signature = pjp.getSignature();
        System.out.println("执行了"+signature);
        System.out.println("环绕后");
    }
}
